package com.breaktian.demoapp.ui;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.breaktian.assemble.utils.LogUtil;
import com.breaktian.assemble.router.RouterError;
import com.breaktian.assemble.router.VpRouter;
import com.breaktian.assemble.router.i.IRouterInterceptor;
import com.breaktian.assemble.router.i.IRouterResultCallback;
import com.breaktian.demoapp.R;
import com.breaktian.demoapp.provider.BaseProvider;
import com.breaktian.demoapp.toobar.ToolBarBuilder;
import com.breaktian.demoapp.ui.base.BaseActivity;
import com.breaktian.demoapp.utils.ToastUtils;

public class TestJumpManagerActivity extends BaseActivity {

    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_jump_manager);

        toolbar = (Toolbar)findViewById(R.id.toolBar);
        new ToolBarBuilder().setToolbar(toolbar).setTitle("你好jump manager").hideBackIcon(false)
                .build(this);

        //跳转到本应用中的activity
        findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                VpRouter.get().activity(TestJumpManagerActivity.this).jump("http://www.baidu.com");
            }
        });
        //跳转到其他应用中的activity
        findViewById(R.id.button6).setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
//                VpRouter.get().setActivity(TestJumpManagerActivity.this).extra("title","testrouter").jump("demo://outapp.mainactivity");
                VpRouter.get().activity(TestJumpManagerActivity.this).extra("name",333).jump("demo://outapp.mainactivity?title=hahahahah");

            }
        });

        //跳转到module中的activity
        findViewById(R.id.button7).setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(TestJumpManagerActivity.this,BaseModuleMainActivity.class);
//                startActivity(intent);

                VpRouter.get()
                        .activity(TestJumpManagerActivity.this)
                        .flags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                        .extra("key","value")
                        .setInterceptor(new IRouterInterceptor() {
                            @Override
                            public boolean cancel() {
                                return false;
                            }

                            @Override
                            public Bundle addExtras() {
                                Bundle bundle = new Bundle();
                                bundle.putString("title","sssss");
                                return bundle;
                            }
                        })
                        .setResultCallback(new IRouterResultCallback() {
                            @Override
                            public void onSuccess() {
                                LogUtil.d("跳转成功");
                                ToastUtils.show("跳转成功");
                            }

                            @Override
                            public void onFail(RouterError error) {
                                LogUtil.d("跳转失败："+error.toString());
                                ToastUtils.show("跳转失败："+error.toString());
                            }
                        })
                        .jumpForResult("demo://basemodule.mainactivity",2);

            }
        });



    }

    @Override
    protected BaseProvider getProvider() {
        return null;
    }
}
